from aiogram import F
from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Back, Start

from poker_bot.tg_bot.states import AddReferralSG, CheckSubscribeSG, DiscountsSG

from ...getters.discounts import discount_info_getter, discounts_getter
from ...getters.users import user_info_getter
from ...reusable_windows import get_list_window
from ...widgets import LocaleText
from .handlers import select_discount

discount_info_window = Window(
    LocaleText("discount-terms", discount_terms="{discount_text}"),
    Start(
        LocaleText("subscribe-btn"),
        id="subscribe_btn",
        state=CheckSubscribeSG.display_social_media,
        when=(F["discount_title"].contains("подписк")) & (~F["is_subscribed"]),
    ),
    Start(
        LocaleText("add-referral-btn"),
        id="add_referral",
        state=AddReferralSG.enter_referral_account_id,
        when=F["discount_title"].contains("друг"),
    ),
    Back(LocaleText("back-btn")),
    state=DiscountsSG.discount_info,
    getter=(discount_info_getter, user_info_getter),
    disable_web_page_preview=True,
)

discounts_dialog = Dialog(
    get_list_window(
        "discounts-list-msg",
        "{item.title}",
        "discounts",
        DiscountsSG.discounts_list,
        discounts_getter,
        select_discount,
    ),
    discount_info_window,
)
